<?php

namespace hiduoke\services\formBuilder\form;

use FormBuilder\Driver\FormComponent;
use FormBuilder\Factory\Elm;

class DkUpload extends FormComponent
{

    public function createValidate()
    {
        return Elm::validateArr();
    }


    /**
     * Dialog 自身是否插入至 body 元素上。
     * @return DkUpload
     */
    public function appendToBody()
    {
        return $this->props(['appendToBody' => true]);
    }

    /**
     * 上传多少个
     * @param $limit
     * @return DkUpload
     */
    public function limit($limit)
    {
        return $this->props(['limit' => $limit]);
    }

    /**
     * 提交地址
     * @param $url
     * @return DkUpload
     */
    public function action($url)
    {
        return $this->props(['actionUrl' => $url]);
    }

    /**
     * 文件类型
     * @param $type
     * @return DkUpload
     */
    public function fileType($type)
    {
        return $this->props(['type' => $type]);
    }

    /**
     * 帮助
     * @param array $help
     * @return DkUpload
     */
    public function help($help)
    {
        $help = is_string($help) ? [$help] : $help;
        return $this->appendRule('suffix', ['type' => 'p', 'class' => 'd-text-grey d-size-12', 'children' => $help]);
    }

    /**
     * 额外参数
     * @param array $data
     * @return DkUpload
     */
    public function data(array $data)
    {
        return $this->props(['data' => $data]);
    }
}
